<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>第 2 页 | YouN 科技温度</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  
  
  
  <meta property="og:type" content="website">
<meta property="og:title" content="YouN 科技温度">
<meta property="og:url" content="http://this4u.cn/page/2/index.html">
<meta property="og:site_name" content="YouN 科技温度">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="Timmy">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="YouN 科技温度" type="application/atom+xml">
  
  <link rel="icon" href="/css/images/favicon.ico">
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link href="https://fonts.googleapis.com/css?family=Open+Sans|Montserrat:700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic" rel="stylesheet" type="text/css">
  <link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
  <style type="text/css">
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/9749f0/00000000000000000001008f/27/l?subset_id=2&fvd=n5) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/90cf9f/000000000000000000010091/27/l?subset_id=2&fvd=n7) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/8a5494/000000000000000000013365/27/l?subset_id=2&fvd=n4) format("woff2");font-weight:lighter;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/d337d8/000000000000000000010095/27/l?subset_id=2&fvd=i4) format("woff2");font-weight:400;font-style:italic;}</style>
    
  <link rel="stylesheet" id="athemes-headings-fonts-css" href="//fonts.googleapis.com/css?family=Yanone+Kaffeesatz%3A200%2C300%2C400%2C700&amp;ver=4.6.1" type="text/css" media="all">

  <link rel="stylesheet" id="athemes-headings-fonts-css" href="//fonts.googleapis.com/css?family=Oswald%3A300%2C400%2C700&amp;ver=4.6.1" type="text/css" media="all">
  
<link rel="stylesheet" href="/css/style.css">


  
<script src="/js/jquery-3.1.1.min.js"></script>


  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="/css/bootstrap.css" >
  <link rel="stylesheet" href="/css/fashion.css" >
  <link rel="stylesheet" href="/css/glyphs.css" >

<meta name="generator" content="Hexo 6.3.0"></head>



  <body>


  


<header id="allheader" class="site-header" role="banner" 
   >
  <div class="clearfix container">
      <div class="site-branding">

          <h1 class="site-title">
            
              <a href="/" rel="home" >
                <img style="margin-bottom: 2px;"  width="126px" height="60px" alt="Hike News" src=" /css/images/youu.jpg">
              </a>
            
          </h1>
          
          
            
          <nav id="main-navigation" class="main-navigation" role="navigation">
            <a class="nav-open">Menu</a>
            <a class="nav-close">Close</a>

            <div class="clearfix sf-menu">
              <ul id="main-nav" class="menu sf-js-enabled sf-arrows"  style="touch-action: pan-y;">
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663" linktext="/"> <a class="" href="/">首页</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663" linktext="archives"> <a class="" href="/archives">归档</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663" linktext="categories"> <a class="" href="/categories">分类</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663" linktext="tags"> <a class="" href="/tags">标签</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663" linktext="about"> <a class="" href="/about">关于</a> </li>
                    
              </ul>
            </div>
          </nav>

      </div>
  </div>
</header>


  <div id="container">
    <div id="wrap">
            
      <div id="content" class="outer">
        
          <section id="main">
  
    <article id="post-docker-mysql"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2020/06/01/docker-mysql/">docker_mysql</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2020/06/01/docker-mysql/" class="article-date">
	  <time datetime="2020-06-01T02:20:46.000Z" itemprop="datePublished">六月 1, 2020</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="拉取镜像"><a href="#拉取镜像" class="headerlink" title="拉取镜像"></a>拉取镜像</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull mysql</span><br></pre></td></tr></table></figure>

<h2 id="启动指令"><a href="#启动指令" class="headerlink" title="启动指令"></a>启动指令</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">简单启动</span></span><br><span class="line">docker run --name mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag</span><br><span class="line"></span><br><span class="line">docker run --name mysql -v /tmp/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=pass -d mysql:tag</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">端口及目录映射</span></span><br><span class="line">docker run --name mysql-3306 -v /tmp/mysql:/var/lib/mysql -p 33060:3306 -e MYSQL_ROOT_PASSWORD=pass -d mysql:tag</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">常用</span></span><br><span class="line">docker run --name mysql-3306 -v /tmp/mysql:/var/lib/mysql -p 33060:3306 -e MYSQL_ROOT_PASSWORD=pass -d mysql --default-authentication-plugin=mysql_native_password</span><br><span class="line"></span><br><span class="line">CREATE USER &#x27;root&#x27;@&#x27;%&#x27; IDENTIFIED BY &#x27;pass&#x27;;</span><br><span class="line">GRANT ALL ON *.* TO &#x27;root&#x27;@&#x27;%&#x27;;</span><br><span class="line">ALTER USER &#x27;root&#x27;@&#x27;%&#x27; IDENTIFIED WITH mysql_native_password BY &#x27;pass&#x27;;</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/docker-mysql/" rel="tag">docker mysql</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-big-endian"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2020/04/26/big-endian/">big_endian</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2020/04/26/big-endian/" class="article-date">
	  <time datetime="2020-04-26T03:00:36.000Z" itemprop="datePublished">四月 26, 2020</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="Big-Endian-and-Little-Endian"><a href="#Big-Endian-and-Little-Endian" class="headerlink" title="Big Endian and Little Endian"></a>Big Endian and Little Endian</h1><p>A load word or store word instruction uses only one memory address. The <strong>lowest address</strong> of the four bytes is used for the address of a block of four contiguous bytes.</p>
<p>How is a 32-bit pattern held in the four bytes of memory? There are 32 bits in the four bytes and 32 bits in the pattern, but a choice has to be made about which byte of memory gets what part of the pattern. There are two ways that computers commonly do this:</p>
<blockquote>
<p><strong>Big Endian Byte Order:</strong> The <strong>most significant</strong> byte (the “big end”) of the data is placed at the byte with the lowest address. The rest of the data is placed in order in the next three bytes in memory.</p>
<p><strong>Little Endian Byte Order:</strong> The <strong>least significant</strong> byte (the “little end”) of the data is placed at the byte with the lowest address. The rest of the data is placed in order in the next three bytes in memory.</p>
</blockquote>
<p><img src="https://chortle.ccsu.edu/AssemblyTutorial/Chapter-15/bigLittleEndian.gif"></p>
<p>In these definitions, the data, a 32-bit pattern, is regarded as a 32-bit unsigned integer. The “most significant” byte is the one for the largest powers of two: 231, …, 224. The “least significant” byte is the one for the smallest powers of two: 27, …, 20.</p>
<p>For example, say that the 32-bit pattern 0x12345678 is stored at address 0x00400000. The most significant byte is 0x12; the least significant is 0x78.</p>
<p>Within a <strong>byte</strong> the order of the bits is the same for all computers (no matter how the bytes themselves are arranged).</p>
<h3 id="一、字节序"><a href="#一、字节序" class="headerlink" title="一、字节序"></a>一、字节序</h3><p><strong>字节序</strong>，也就是字节的顺序，指的是多字节的数据在内存中的存放顺序。</p>
<p>在几乎所有的机器上，多字节对象都被存储为连续的字节序列。例如：如果C&#x2F;C++中的一个<code>int</code>型变量 a 的起始地址是<code>&amp;a = 0x100</code>，那么 a 的四个字节将被存储在存储器的<code>0x100</code>, <code>0x101</code>, <code>0x102</code>, <code>0x103</code>位置。</p>
<p>根据整数 a 在连续的 4 byte 内存中的存储顺序，字节序被分为<strong>大端序（Big Endian）</strong> 与 <strong>小端序（Little Endian）</strong>两类。 然后就牵涉出两大CPU派系：</p>
<ul>
<li>Motorola 6800，PowerPC 970，SPARC（除V9外）等处理器采用 Big Endian方式存储数据；</li>
<li>x86系列，VAX，PDP-11等处理器采用Little Endian方式存储数据。</li>
</ul>
<p>另外，还有一些处理器像ARM, DEC Alpha的字节序是可配置的。</p>
<h3 id="二、大端与小端"><a href="#二、大端与小端" class="headerlink" title="二、大端与小端"></a>二、大端与小端</h3><p>那么，到底什么是大端，什么是小端？ 如下图：</p>
<p><a target="_blank" rel="noopener" href="http://img.blog.csdn.net/20150501200116979"><img src="http://img.blog.csdn.net/20150501200116979" alt="img"></a></p>
<p>我相信上面的图已经够直观了。也就是说：</p>
<ul>
<li>Big Endian 是指低地址端 存放 高位字节。</li>
<li>Little Endian 是指低地址端 存放 低位字节。</li>
</ul>
<p><strong>各自的优势：</strong></p>
<ol>
<li>Big Endian：符号位的判定固定为第一个字节，容易判断正负。</li>
<li>Little Endian：长度为1，2，4字节的数，排列方式都是一样的，数据类型转换非常方便。</li>
</ol>
<h3 id="三、为什么要注意字节序"><a href="#三、为什么要注意字节序" class="headerlink" title="三、为什么要注意字节序"></a>三、为什么要注意字节序</h3><p>如果你写的程序只在单机环境下面运行，并且不和别人的程序打交道，那么你完全可以忽略字节序的存在。</p>
<p>但是，如果你的程序要跟别人的程序产生交互呢？ 比如，当一个 C&#x2F;C++ 的程序要与一个 Java 程序交互时：</p>
<ul>
<li>C&#x2F;C++语言编写的程序里数据存储顺序是跟编译平台所在的CPU相关的，而现在比较普遍的 x86 处理器是 Little Endian</li>
<li>JAVA编写的程序则唯一采用 Big Endian 方式来存储数据</li>
</ul>
<p>试想，如果你的C&#x2F;C++程序将变量 <code>a = 0x12345678</code> 的首地址传递给了Java程序，由于Java采取 Big Endian 方式存储数据，很自然的它会将你的数据翻译为 <code>0x78563412</code>。显然，问题就出现了！！！</p>
<p>另外，网络传输一般采用 Big Endian，也被称之为<strong>网络字节序</strong>，或<strong>网络序</strong>。当两台采用不同字节序的主机通信时，在发送数据之前都必须经过字节序的转换成为网络字节序后再进行传输。</p>
<h3 id="四、判断机器的字节序"><a href="#四、判断机器的字节序" class="headerlink" title="四、判断机器的字节序"></a>四、判断机器的字节序</h3><p>由于 C&#x2F;C++ 存储数据时的字节序依赖所在平台的CPU，所以我们可以通过C&#x2F;C++程序判定机器的端序：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">void Endianness()</span><br><span class="line">&#123;</span><br><span class="line">	int a = 0x12345678;</span><br><span class="line">	if( *((char*)&amp;a) == 0x12)</span><br><span class="line">		cout &lt;&lt; &quot;Big Endian&quot; &lt;&lt; endl;</span><br><span class="line">	else</span><br><span class="line">		cout &lt;&lt; &quot;Little Endian&quot; &lt;&lt; endl;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>





<h3 id="五、网络序和主机序"><a href="#五、网络序和主机序" class="headerlink" title="五、网络序和主机序"></a>五、网络序和主机序</h3><p><strong>网络字节序</strong>：TCP&#x2F;IP各层协议将字节序定义为 Big Endian，因此TCP&#x2F;IP协议中使用的字节序是大端序。</p>
<p><strong>主机字节序</strong>：整数在内存中存储的顺序，现在 Little Endian 比较普遍。（不同的 CPU 有不同的字节序）</p>
<p>在进行网络通信时 通常需要调用相应的函数进行主机序和网络序的转换。Berkeley socket API 定义了一组转换函数，用于16和32bit整数在网络序和本机字节序之间的转换。htonl，htons用于本机序转换到网络序；ntohl，ntohs用于网络序转换到本机序。</p>

      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Endian-%E5%AD%97%E8%8A%82%E5%BA%8F-%E7%BD%91%E7%BB%9C%E9%80%9A%E4%BF%A1/" rel="tag">Endian 字节序 网络通信</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-iptables"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2020/04/24/iptables/">iptables</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2020/04/24/iptables/" class="article-date">
	  <time datetime="2020-04-24T06:28:14.000Z" itemprop="datePublished">四月 24, 2020</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="netstat"><a href="#netstat" class="headerlink" title="## netstat"></a>## netstat</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">-a或--all：显示所有连线中的Socket；</span><br><span class="line">-A&lt;网络类型&gt;或--&lt;网络类型&gt;：列出该网络类型连线中的相关地址；</span><br><span class="line">-c或--continuous：持续列出网络状态；</span><br><span class="line">-C或--cache：显示路由器配置的快取信息；</span><br><span class="line">-e或--extend：显示网络其他相关信息；</span><br><span class="line">-F或--fib：显示FIB；</span><br><span class="line">-g或--groups：显示多重广播功能群组组员名单；</span><br><span class="line">-h或--help：在线帮助；</span><br><span class="line">-i或--interfaces：显示网络界面信息表单；</span><br><span class="line">-l或--listening：显示监控中的服务器的Socket；</span><br><span class="line">-M或--masquerade：显示伪装的网络连线；</span><br><span class="line">-n或--numeric：直接使用ip地址，而不通过域名服务器；</span><br><span class="line">-N或--netlink或--symbolic：显示网络硬件外围设备的符号连接名称；</span><br><span class="line">-o或--timers：显示计时器；</span><br><span class="line">-p或--programs：显示正在使用Socket的程序识别码和程序名称；</span><br><span class="line">-r或--route：显示Routing Table；</span><br><span class="line">-s或--statistice：显示网络工作信息统计表；</span><br><span class="line">-t或--tcp：显示TCP传输协议的连线状况；</span><br><span class="line">-u或--udp：显示UDP传输协议的连线状况；</span><br><span class="line">-v或--verbose：显示指令执行过程；</span><br><span class="line">-V或--version：显示版本信息；</span><br><span class="line">-w或--raw：显示RAW传输协议的连线状况；</span><br><span class="line">-x或--unix：此参数的效果和指定&quot;-A unix&quot;参数相同；</span><br><span class="line">--ip或--inet：此参数的效果和指定&quot;-A inet&quot;参数相同。</span><br></pre></td></tr></table></figure>



<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">netstat -a     #列出所有端口</span><br><span class="line">netstat -at    #列出所有tcp端口</span><br><span class="line">netstat -au    #列出所有udp端口</span><br><span class="line"></span><br><span class="line">netstat -l        #只显示监听端口</span><br><span class="line">netstat -lt       #只列出所有监听 tcp 端口</span><br><span class="line">netstat -lu       #只列出所有监听 udp 端口</span><br><span class="line">netstat -lx       #只列出所有监听 UNIX 端口</span><br><span class="line"></span><br><span class="line">netstat -s   #显示所有端口的统计信息</span><br><span class="line">netstat -st   #显示TCP端口的统计信息</span><br><span class="line">netstat -su   #显示UDP端口的统计信息</span><br><span class="line"></span><br><span class="line">netstat -pt		#在netstat输出中显示 PID 和进程名称</span><br><span class="line"></span><br><span class="line">netstat -ntu | grep :80 | awk &#x27;&#123;print $5&#125;&#x27; | cut -d: -f1 | awk &#x27;&#123;++ip[$1]&#125; END &#123;for(i in ip) print ip[i],&quot;\t&quot;,i&#125;&#x27; | sort -nr  #查看连接某服务端口最多的的IP地址</span><br><span class="line"></span><br><span class="line">netstat -nt | grep -e 127.0.0.1 -e 0.0.0.0 -e ::: -v | awk &#x27;/^tcp/ &#123;++state[$NF]&#125; END &#123;for(i in state) print i,&quot;\t&quot;,state[i]&#125;&#x27;	#TCP各种状态列表</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h2 id="iptables"><a href="#iptables" class="headerlink" title="iptables"></a>iptables</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">-t&lt;表&gt;：指定要操纵的表；</span><br><span class="line">-A：向规则链中添加条目；</span><br><span class="line">-D：从规则链中删除条目；</span><br><span class="line">-i：向规则链中插入条目；</span><br><span class="line">-R：替换规则链中的条目；</span><br><span class="line">-L：显示规则链中已有的条目；</span><br><span class="line">-F：清楚规则链中已有的条目；</span><br><span class="line">-Z：清空规则链中的数据包计算器和字节计数器；</span><br><span class="line">-N：创建新的用户自定义规则链；</span><br><span class="line">-P：定义规则链中的默认目标；</span><br><span class="line">-h：显示帮助信息；</span><br><span class="line">-p：指定要匹配的数据包协议类型；</span><br><span class="line">-s：指定要匹配的数据包源ip地址；</span><br><span class="line">-j&lt;目标&gt;：指定要跳转的目标；</span><br><span class="line">-i&lt;网络接口&gt;：指定数据包进入本机的网络接口；</span><br><span class="line">-o&lt;网络接口&gt;：指定数据包要离开本机所使用的网络接口。</span><br></pre></td></tr></table></figure>



<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">iptables -t 表名 &lt;-A/I/D/R&gt; 规则链名 [规则号] &lt;-i/o 网卡名&gt; -p 协议名 &lt;-s 源IP/源子网&gt; --sport 源端口 &lt;-d 目标IP/目标子网&gt; --dport 目标端口 -j 动作</span><br></pre></td></tr></table></figure>



<h3 id="清除已有规则"><a href="#清除已有规则" class="headerlink" title="清除已有规则"></a>清除已有规则</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">iptables -F</span><br><span class="line">iptables -X</span><br><span class="line">iptables -Z</span><br><span class="line">iptables -L -n --line-number  #显示编号</span><br><span class="line">iptables -D INPUT 2  #删除INPUT链编号为2的规则</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT               #允许本地回环接口(即运行本机访问本机)</span><br><span class="line">iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT    #允许已建立的或相关连的通行</span><br><span class="line">iptables -A OUTPUT -j ACCEPT         #允许所有本机向外的访问</span><br><span class="line">iptables -A INPUT -p tcp --dport 22 -j ACCEPT    #允许访问22端口</span><br><span class="line">iptables -A INPUT -p tcp --dport 80 -j ACCEPT    #允许访问80端口</span><br><span class="line">iptables -A INPUT -p tcp --dport 21 -j ACCEPT    #允许ftp服务的21端口</span><br><span class="line">iptables -A INPUT -p tcp --dport 20 -j ACCEPT    #允许FTP服务的20端口</span><br><span class="line">iptables -A INPUT -j REJECT       #禁止其他未允许的规则访问</span><br><span class="line">iptables -A FORWARD -j REJECT     #禁止其他未允许的规则访问</span><br></pre></td></tr></table></figure>



<h3 id="样例"><a href="#样例" class="headerlink" title="样例"></a>样例</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo iptables -I FORWARD -p tcp --dport 8080 -j DROP  # 不响应对8080的请求，等待超时（效果：Operation timed out）</span><br><span class="line">sudo iptables -I INPUT -p tcp --dport 8080 -j REJECT  # 直接拒绝其他机器连接本机8080 （效果：Connection refused）</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Linux-Iptables-Netstat-%E7%AB%AF%E5%8F%A3/" rel="tag">Linux Iptables Netstat 端口</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-nginx-gray"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2019/11/20/nginx-gray/">nginx-gray</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2019/11/20/nginx-gray/" class="article-date">
	  <time datetime="2019-11-20T09:52:25.000Z" itemprop="datePublished">十一月 20, 2019</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="Nginx-灰度测试"><a href="#Nginx-灰度测试" class="headerlink" title="Nginx 灰度测试"></a>Nginx 灰度测试</h2><blockquote>
<p>灰度测试在系统重构过程中是必不可少的，很多公司有自己的灰度解决方案。对于初创型或者小型团队，缺少必要的工具，因此这里借用nginx的转发（反向代理）能力做一下灰度测试。</p>
</blockquote>
<h2 id="Nginx配置"><a href="#Nginx配置" class="headerlink" title="Nginx配置"></a>Nginx配置</h2><h3 id="Nginx配置文件主要分4部分"><a href="#Nginx配置文件主要分4部分" class="headerlink" title="Nginx配置文件主要分4部分"></a>Nginx配置文件主要分4部分</h3><ul>
<li><strong>main(全局设置)：</strong>  main部分的指令将影响其他所有的设置</li>
<li><strong>server(主机设置)：</strong> server部分的指令主要作用于指定的主机和端口</li>
<li><strong>upstream(负载均衡服务器设置)：</strong> upstream指令主要作用于负载均衡的设置</li>
<li><strong>location(指定网页的设置):</strong> 主要用于匹配上的网页的设置。首先匹配 &#x3D;，其次匹配^~, 其次是按文件中顺序的正则匹配，最后是交给 &#x2F; 通用匹配。当有匹配成功时候，停止匹配，按当前匹配规则处理请求。</li>
</ul>
<h3 id="proxy-pass"><a href="#proxy-pass" class="headerlink" title="proxy_pass"></a>proxy_pass</h3><blockquote>
<p>在nginx中配置proxy_pass代理转发时，如果在proxy_pass后面的url加&#x2F;，表示绝对根路径；如果没有&#x2F;，表示相对路径，把匹配的路径部分也给代理走。</p>
</blockquote>
<p>假设下面四种情况分别用 <a target="_blank" rel="noopener" href="http://192.168.1.1/proxy/test.html">http://192.168.1.1/proxy/test.html</a> 进行访问。</p>
<p><strong>CASE 1:</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">location /proxy/ &#123;</span><br><span class="line">    proxy_pass http://127.0.0.1/;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>代理到URL：<a target="_blank" rel="noopener" href="http://127.0.0.1/test.html">http://127.0.0.1/test.html</a></p>
<p><strong>CASE 2:</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">location /proxy/ &#123;</span><br><span class="line">    proxy_pass http://127.0.0.1;#少了一个/</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>代理到URL：<a target="_blank" rel="noopener" href="http://127.0.0.1/proxy/test.html">http://127.0.0.1/proxy/test.html</a></p>
<p><strong>CASE 3:</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">location /proxy/ &#123;</span><br><span class="line">    proxy_pass http://127.0.0.1/v1/;#加了一个子路径</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>代理到URL：<a target="_blank" rel="noopener" href="http://127.0.0.1/v1/test.html">http://127.0.0.1/v1/test.html</a></p>
<p><strong>CASE 4:</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">location /proxy/ &#123;</span><br><span class="line">    proxy_pass http://127.0.0.1/v1;#加了一个前缀</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>代理到URL：<a target="_blank" rel="noopener" href="http://127.0.0.1/v1test.html">http://127.0.0.1/v1test.html</a></p>
<h2 id="灰度粒度"><a href="#灰度粒度" class="headerlink" title="灰度粒度"></a>灰度粒度</h2><h3 id="URL级别"><a href="#URL级别" class="headerlink" title="URL级别"></a>URL级别</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">location  /api_to_gray &#123;</span><br><span class="line">	proxy_pass http://target_endpoint/api_to_gray;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="参数级别"><a href="#参数级别" class="headerlink" title="参数级别"></a>参数级别</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">location  /api_to_gray &#123;</span><br><span class="line">  //$arg_param 是url里面的参数，$http_param 是header里面的参数</span><br><span class="line">  if ($arg_param = &quot;value&quot;)&#123;</span><br><span class="line">    add_header Version &#x27;V2&#x27;;</span><br><span class="line">    proxy_pass http://target_endpoint/api_to_gray;</span><br><span class="line">  &#125;</span><br><span class="line">	proxy_pass http://original_endpoint;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>





<h2 id="参考文档"><a href="#参考文档" class="headerlink" title="参考文档"></a>参考文档</h2><p><a target="_blank" rel="noopener" href="http://yzone.net/blog/53">Nginx 内置变量</a></p>

      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/nginx-%E7%81%B0%E5%BA%A6/" rel="tag">nginx 灰度</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-file-diff"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2019/11/06/file-diff/">Linux 文件对比命令</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2019/11/06/file-diff/" class="article-date">
	  <time datetime="2019-11-06T05:34:37.000Z" itemprop="datePublished">十一月 6, 2019</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="comm-指令"><a href="#comm-指令" class="headerlink" title="comm 指令"></a>comm 指令</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">comm [-123][--help][--version][第1个文件][第2个文件]</span><br></pre></td></tr></table></figure>

<p><strong>参数</strong>：</p>
<ul>
<li>-1 不显示只在第1个文件里出现过的列。</li>
<li>-2 不显示只在第2个文件里出现过的列。</li>
<li>-3 不显示只在第1和第2个文件里出现过的列。</li>
<li>–help 在线帮助。</li>
<li>–version 显示版本信息。</li>
</ul>
<blockquote>
<p>需要排序，即便排序也不一定正确，所以不建议使用，适合对比极少数同行差异的文件。</p>
</blockquote>
<h2 id="diff-指令"><a href="#diff-指令" class="headerlink" title="diff 指令"></a>diff 指令</h2><p>同comm指令，也是逐行对比，如果同样的内容处于不同行中，对比结果也不是期望的</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">diff [-abBcdefHilnNpPqrstTuvwy][-&lt;行数&gt;][-C &lt;行数&gt;][-D &lt;巨集名称&gt;][-I &lt;字符或字符串&gt;][-S &lt;文件&gt;][-W &lt;宽度&gt;][-x &lt;文件或目录&gt;][-X &lt;文件&gt;][--help][--left-column][--suppress-common-line][文件或目录1][文件或目录2]</span><br></pre></td></tr></table></figure>

<h2 id="grep-指令"><a href="#grep-指令" class="headerlink" title="grep 指令"></a>grep 指令</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grep [-abcEFGhHilLnqrsvVwxy][-A&lt;显示列数&gt;][-B&lt;显示列数&gt;][-C&lt;显示列数&gt;][-d&lt;进行动作&gt;][-e&lt;范本样式&gt;][-f&lt;范本文件&gt;][--help][范本样式][文件或目录...]</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">查看file2比file1多出的内容</span></span><br><span class="line">grep -v -x -f file1 file2</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">查看file1和file2中单独存在的内容（差集1+差集2）</span></span><br><span class="line">grep -v -x -f file1 file2 &amp;&amp;  grep -v -x -f file2 file1 </span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">查看file1和file2的交集</span></span><br><span class="line">grep -x -f file1 file2</span><br></pre></td></tr></table></figure>

<blockquote>
<p>-x –line-regexp : 只显示全列符合的列。</p>
<p>-f &lt;规则文件&gt; 或 –file&#x3D;&lt;规则文件&gt;: 指定规则文件，其内容含有一个或多个规则样式，让grep查找符合规则条件的文件内容，格式为每行一个规则样式。</p>
</blockquote>

      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Linux-diff-comm-grep/" rel="tag">Linux diff comm grep</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-nginx-variables"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2019/10/15/nginx-variables/">nginx-variables</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2019/10/15/nginx-variables/" class="article-date">
	  <time datetime="2019-10-15T11:44:12.000Z" itemprop="datePublished">十月 15, 2019</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="Nginx-内置变量大全"><a href="#Nginx-内置变量大全" class="headerlink" title="Nginx 内置变量大全"></a>Nginx 内置变量大全</h2><p><a target="_blank" rel="noopener" href="https://github.com/nginx/nginx/blob/master/src/http/ngx_http_variables.c">源码</a></p>
<figure class="highlight tex"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">$</span>args //请求中的的参数名，即“?”后面的arg<span class="built_in">_</span>name=arg<span class="built_in">_</span>value形式的arg<span class="built_in">_</span>name</span><br><span class="line"><span class="built_in">$</span>arg<span class="built_in">_</span>PARAMETER //这是参数的一个匹配模式,PARAMETER为具体的参数名,<span class="built_in">$</span>arg<span class="built_in">_</span>PARAMETER就表示获取具体的参数值,例如上面的<span class="built_in">$</span>arg<span class="built_in">_</span>name就是获取url中name的值</span><br><span class="line"><span class="built_in">$</span>is<span class="built_in">_</span>args //判断url是否带参数，如果带，则返回一个？,否则返回一个空字符串</span><br><span class="line"></span><br><span class="line"><span class="built_in">$</span>http<span class="built_in">_</span>user<span class="built_in">_</span>agent //获取的是客户端访问代理的类型,请求头中的信息</span><br><span class="line"><span class="built_in">$</span>sent<span class="built_in">_</span>http<span class="built_in">_</span>content<span class="built_in">_</span>type //获取的是http响应头中content<span class="built_in">_</span>type的值</span><br><span class="line"><span class="built_in">$</span>sent<span class="built_in">_</span>http<span class="built_in">_</span>content<span class="built_in">_</span>length //获取的是http响应头重的content<span class="built_in">_</span>length的值</span><br><span class="line"></span><br><span class="line"><span class="built_in">$</span>request<span class="built_in">_</span>filename  //该变量获取的是请求的文件在linux服务器上的完整的绝对路径</span><br><span class="line"><span class="built_in">$</span>request<span class="built_in">_</span>method  //该表示获取的是http请求的方法</span><br><span class="line"><span class="built_in">$</span>request<span class="built_in">_</span>uri  //该变量表示的原始请求的uri，包括参数。所谓原始请求就是即使在内部做了重定向之后也不会变化</span><br><span class="line"><span class="built_in">$</span>uri  //获取的是当前请求的uri，不包括参数</span><br><span class="line"><span class="built_in">$</span>content<span class="built_in">_</span>length  //获取的是http请求头中Content-Length的值</span><br><span class="line"><span class="built_in">$</span>content<span class="built_in">_</span>type   //获取的是http请求头中的Content-Type字段，不过这里也没显示。。。</span><br><span class="line"><span class="built_in">$</span>document<span class="built_in">_</span>root   //获取的是请求url的文件所在的目录路径</span><br><span class="line"><span class="built_in">$</span>document<span class="built_in">_</span>uri   //当前请求的uri，从上面的信息来看,和uri的效果是一样的</span><br><span class="line"><span class="built_in">$</span>remote<span class="built_in">_</span>addr  //获取的是客户端的ip地址,这里为什么是10.0.10.11呢，因为我是在本机上用curl测试的，即使客户端也是服务器</span><br><span class="line"><span class="built_in">$</span>remote<span class="built_in">_</span>port  //获取客户端的访问端口，这个端口是随机的</span><br><span class="line"><span class="built_in">$</span>remote<span class="built_in">_</span>user  //获取客户端的认证用户信息，这里因为没有用认证，所谓显示为空</span><br><span class="line"><span class="built_in">$</span>server<span class="built_in">_</span>protocol  //表示服务器端想客户端发送响应的协议</span><br><span class="line"><span class="built_in">$</span>server<span class="built_in">_</span>addr  //服务器的地址</span><br><span class="line"><span class="built_in">$</span>server<span class="built_in">_</span>name  //客户端访问服务端的域名，即url中的域名(通配符不自动解析)</span><br><span class="line"><span class="built_in">$</span>server<span class="built_in">_</span>port //服务器端做出响应的端口号</span><br><span class="line"><span class="built_in">$</span>binary<span class="built_in">_</span>remote<span class="built_in">_</span>addr  //显示二进制的客户端地址</span><br><span class="line"><span class="built_in">$</span>host  //和server<span class="built_in">_</span>name一样，表示的是域名</span><br><span class="line"><span class="built_in">$</span>hostname  //表示服务器端的主机名</span><br><span class="line"></span><br><span class="line"><span class="built_in">$</span>proxy<span class="built_in">_</span>add<span class="built_in">_</span>x<span class="built_in">_</span>forwarded<span class="built_in">_</span>for //获取的是客户端的真实ip地址</span><br><span class="line"><span class="built_in">$</span>proxy<span class="built_in">_</span>host //该变量获取的是upstream的上游代理名称，例如upstream backend </span><br><span class="line"><span class="built_in">$</span>proxy<span class="built_in">_</span>port   //该变量表示的是要代理到的端口</span><br><span class="line"><span class="built_in">$</span>proxy<span class="built_in">_</span>protocol<span class="built_in">_</span>addr  //代理头部中客户端的ip地址，或者是一个空的字符串</span><br><span class="line"><span class="built_in">$</span>upstream<span class="built_in">_</span>addr  //代理到上游的服务器地址信息</span><br><span class="line"><span class="built_in">$</span>upstream<span class="built_in">_</span>cache<span class="built_in">_</span>status    //proxy的缓存状态，例如这里第一次访问为MISS，第二次访问时为HIT</span><br><span class="line"><span class="built_in">$</span>upstream<span class="built_in">_</span>response<span class="built_in">_</span>length  //上游服务器响应报文的长度</span><br><span class="line"><span class="built_in">$</span>upstream<span class="built_in">_</span>response<span class="built_in">_</span>time  //上游服务器响应的时间</span><br><span class="line"><span class="built_in">$</span>upstream<span class="built_in">_</span>status  //上游服务器响应的状态码</span><br><span class="line"></span><br><span class="line"><span class="built_in">$</span>scheme  //表示的是使用http的访问协议 http or https</span><br><span class="line"><span class="built_in">$</span>limit<span class="built_in">_</span>rate  //表示当前连接的限速是多少，0表示无限制</span><br><span class="line"><span class="built_in">$</span>query<span class="built_in">_</span>string  //表示的是查询字符串，也就是url中的参数，和<span class="built_in">$</span>args一样</span><br><span class="line"><span class="built_in">$</span>realpath<span class="built_in">_</span>root  //表示的是请求页面的真实所在目录的路径  和<span class="built_in">$</span>document<span class="built_in">_</span>root是一样的</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/nginx/" rel="tag">nginx</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-proxy-in-mybatis"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2019/10/11/proxy-in-mybatis/">proxy-in-mybatis</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2019/10/11/proxy-in-mybatis/" class="article-date">
	  <time datetime="2019-10-11T11:02:19.000Z" itemprop="datePublished">十月 11, 2019</time>
	</a>

      
	<span class="ico-folder"></span>
    <a class="article-category-link" href="/categories/Mybatis/">Mybatis</a>
 
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="代理在Mybatis里面的使用"><a href="#代理在Mybatis里面的使用" class="headerlink" title="代理在Mybatis里面的使用"></a>代理在Mybatis里面的使用</h2><blockquote>
<p>主要位于org.apache.ibatis.binding包里面</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">MapperRegistry  负责注册获取Mapper</span><br><span class="line">MapperProxy  Mapper接口的代理</span><br></pre></td></tr></table></figure>

<p><img src="/images/image-20210816113311699.png" alt="binding"></p>
<h2 id="代理实现"><a href="#代理实现" class="headerlink" title="代理实现"></a>代理实现</h2><blockquote>
<p>org.apache.ibatis.session.defaults.DefaultSqlSession#getMapper  </p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">SqlSession.getMapper</span><br><span class="line">  ---&gt; Configuration.getMapper </span><br><span class="line">      ---&gt; MapperRegistry.getMapper </span><br><span class="line">        ---&gt; mapperProxyFactory.newInstance </span><br><span class="line">          ---&gt; Proxy.newProxyInstance</span><br></pre></td></tr></table></figure>

</blockquote>
<blockquote>
<p>command 来自 mapper的注解或者xml配置</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// org.apache.ibatis.binding.MapperMethod#execute</span></span><br><span class="line"><span class="keyword">public</span> Object <span class="title function_">execute</span><span class="params">(SqlSession sqlSession, Object[] args)</span> &#123;</span><br><span class="line">    Object result;</span><br><span class="line">    <span class="keyword">switch</span> (command.getType()) &#123;</span><br><span class="line">      <span class="keyword">case</span> INSERT: &#123;</span><br><span class="line">        <span class="type">Object</span> <span class="variable">param</span> <span class="operator">=</span> method.convertArgsToSqlCommandParam(args);</span><br><span class="line">        result = rowCountResult(sqlSession.insert(command.getName(), param));</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="keyword">case</span> UPDATE: &#123;</span><br><span class="line">        <span class="type">Object</span> <span class="variable">param</span> <span class="operator">=</span> method.convertArgsToSqlCommandParam(args);</span><br><span class="line">        result = rowCountResult(sqlSession.update(command.getName(), param));</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="keyword">case</span> DELETE: &#123;</span><br><span class="line">        <span class="type">Object</span> <span class="variable">param</span> <span class="operator">=</span> method.convertArgsToSqlCommandParam(args);</span><br><span class="line">        result = rowCountResult(sqlSession.delete(command.getName(), param));</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="keyword">case</span> SELECT:</span><br><span class="line">        <span class="keyword">if</span> (method.returnsVoid() &amp;&amp; method.hasResultHandler()) &#123;</span><br><span class="line">          executeWithResultHandler(sqlSession, args);</span><br><span class="line">          result = <span class="literal">null</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (method.returnsMany()) &#123;</span><br><span class="line">          result = executeForMany(sqlSession, args);</span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (method.returnsMap()) &#123;</span><br><span class="line">          result = executeForMap(sqlSession, args);</span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (method.returnsCursor()) &#123;</span><br><span class="line">          result = executeForCursor(sqlSession, args);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">          <span class="type">Object</span> <span class="variable">param</span> <span class="operator">=</span> method.convertArgsToSqlCommandParam(args);</span><br><span class="line">          result = sqlSession.selectOne(command.getName(), param);</span><br><span class="line">          <span class="keyword">if</span> (method.returnsOptional()</span><br><span class="line">              &amp;&amp; (result == <span class="literal">null</span> || !method.getReturnType().equals(result.getClass()))) &#123;</span><br><span class="line">            result = Optional.ofNullable(result);</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      <span class="keyword">case</span> FLUSH:</span><br><span class="line">        result = sqlSession.flushStatements();</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">      <span class="keyword">default</span>:</span><br><span class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">BindingException</span>(<span class="string">&quot;Unknown execution method for: &quot;</span> + command.getName());</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> (result == <span class="literal">null</span> &amp;&amp; method.getReturnType().isPrimitive() &amp;&amp; !method.returnsVoid()) &#123;</span><br><span class="line">      <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">BindingException</span>(<span class="string">&quot;Mapper method &#x27;&quot;</span> + command.getName()</span><br><span class="line">          + <span class="string">&quot; attempted to return null from a method with a primitive return type (&quot;</span> + method.getReturnType() + <span class="string">&quot;).&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> result;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>


      
    </div>
    <footer class="entry-meta entry-footer">
      
	<span class="ico-folder"></span>
    <a class="article-category-link" href="/categories/Mybatis/">Mybatis</a>

      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Mybatis-Proxy/" rel="tag">Mybatis Proxy</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-mybatis-unscramble"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2019/09/24/mybatis-unscramble/">Mybatis源码解读</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2019/09/24/mybatis-unscramble/" class="article-date">
	  <time datetime="2019-09-24T11:54:35.000Z" itemprop="datePublished">九月 24, 2019</time>
	</a>

      
	<span class="ico-folder"></span>
    <a class="article-category-link" href="/categories/Mybatis/">Mybatis</a>
 
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="整体代码结构"><a href="#整体代码结构" class="headerlink" title="整体代码结构"></a>整体代码结构</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">└── org</span><br><span class="line">    └── apache</span><br><span class="line">        └── ibatis</span><br><span class="line">            ├── annotations</span><br><span class="line">            ├── binding</span><br><span class="line">            ├── builder</span><br><span class="line">            ├── cache</span><br><span class="line">            ├── cursor</span><br><span class="line">            ├── datasource</span><br><span class="line">            ├── exceptions</span><br><span class="line">            ├── executor</span><br><span class="line">            ├── io</span><br><span class="line">            ├── jdbc</span><br><span class="line">            ├── lang</span><br><span class="line">            ├── logging</span><br><span class="line">            ├── mapping</span><br><span class="line">            ├── package-info.java</span><br><span class="line">            ├── parsing</span><br><span class="line">            ├── plugin</span><br><span class="line">            ├── reflection</span><br><span class="line">            ├── scripting</span><br><span class="line">            ├── session</span><br><span class="line">            ├── transaction</span><br><span class="line">            ├── type</span><br><span class="line">            └── util</span><br></pre></td></tr></table></figure>



<h2 id="几个核心包"><a href="#几个核心包" class="headerlink" title="几个核心包"></a>几个核心包</h2><h3 id="Executor"><a href="#Executor" class="headerlink" title="Executor"></a>Executor</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line">├── BaseExecutor.java</span><br><span class="line">├── BatchExecutor.java</span><br><span class="line">├── BatchExecutorException.java</span><br><span class="line">├── BatchResult.java</span><br><span class="line">├── CachingExecutor.java</span><br><span class="line">├── ErrorContext.java</span><br><span class="line">├── ExecutionPlaceholder.java</span><br><span class="line">├── Executor.java</span><br><span class="line">├── ExecutorException.java</span><br><span class="line">├── ResultExtractor.java</span><br><span class="line">├── ReuseExecutor.java</span><br><span class="line">├── SimpleExecutor.java</span><br><span class="line">├── keygen</span><br><span class="line">│   ├── Jdbc3KeyGenerator.java</span><br><span class="line">│   ├── KeyGenerator.java</span><br><span class="line">│   ├── NoKeyGenerator.java</span><br><span class="line">│   ├── SelectKeyGenerator.java</span><br><span class="line">│   └── package-info.java</span><br><span class="line">├── loader</span><br><span class="line">│   ├── AbstractEnhancedDeserializationProxy.java</span><br><span class="line">│   ├── AbstractSerialStateHolder.java</span><br><span class="line">│   ├── CglibProxyFactory.java</span><br><span class="line">│   ├── JavassistProxyFactory.java</span><br><span class="line">│   ├── ProxyFactory.java</span><br><span class="line">│   ├── ResultLoader.java</span><br><span class="line">│   ├── ResultLoaderMap.java</span><br><span class="line">│   ├── WriteReplaceInterface.java</span><br><span class="line">│   ├── cglib</span><br><span class="line">│   ├── javassist</span><br><span class="line">│   └── package-info.java</span><br><span class="line">├── package-info.java</span><br><span class="line">├── parameter</span><br><span class="line">│   ├── ParameterHandler.java</span><br><span class="line">│   └── package-info.java</span><br><span class="line">├── result</span><br><span class="line">│   ├── DefaultMapResultHandler.java</span><br><span class="line">│   ├── DefaultResultContext.java</span><br><span class="line">│   ├── DefaultResultHandler.java</span><br><span class="line">│   ├── ResultMapException.java</span><br><span class="line">│   └── package-info.java</span><br><span class="line">├── resultset</span><br><span class="line">│   ├── DefaultResultSetHandler.java</span><br><span class="line">│   ├── ResultSetHandler.java</span><br><span class="line">│   ├── ResultSetWrapper.java</span><br><span class="line">│   └── package-info.java</span><br><span class="line">└── statement</span><br><span class="line">    ├── BaseStatementHandler.java</span><br><span class="line">    ├── CallableStatementHandler.java</span><br><span class="line">    ├── PreparedStatementHandler.java</span><br><span class="line">    ├── RoutingStatementHandler.java</span><br><span class="line">    ├── SimpleStatementHandler.java</span><br><span class="line">    ├── StatementHandler.java</span><br><span class="line">    ├── StatementUtil.java</span><br><span class="line">    └── package-info.java</span><br></pre></td></tr></table></figure>



<h3 id="Session"><a href="#Session" class="headerlink" title="Session"></a>Session</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">├── AutoMappingBehavior.java</span><br><span class="line">├── AutoMappingUnknownColumnBehavior.java</span><br><span class="line">├── Configuration.java</span><br><span class="line">├── ExecutorType.java</span><br><span class="line">├── LocalCacheScope.java</span><br><span class="line">├── ResultContext.java</span><br><span class="line">├── ResultHandler.java</span><br><span class="line">├── RowBounds.java</span><br><span class="line">├── SqlSession.java</span><br><span class="line">├── SqlSessionException.java</span><br><span class="line">├── SqlSessionFactory.java</span><br><span class="line">├── SqlSessionFactoryBuilder.java</span><br><span class="line">├── SqlSessionManager.java</span><br><span class="line">├── TransactionIsolationLevel.java</span><br><span class="line">├── defaults</span><br><span class="line">└── package-info.java</span><br></pre></td></tr></table></figure>



<h2 id="数据库连接打开"><a href="#数据库连接打开" class="headerlink" title="数据库连接打开"></a>数据库连接打开</h2><p><code>org.apache.ibatis.transaction.jdbc.JdbcTransaction#openConnection</code></p>
<h2 id="Mapper-生成"><a href="#Mapper-生成" class="headerlink" title="Mapper 生成"></a>Mapper 生成</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">T org.apache.ibatis.session.defaults.DefaultSqlSession#getMapper</span><br><span class="line">T org.apache.ibatis.session.Configuration#getMapper</span><br><span class="line">T org.apache.ibatis.binding.MapperRegistry#getMapper</span><br><span class="line">T org.apache.ibatis.binding.MapperProxyFactory#newInstance(org.apache.ibatis.session.SqlSession)</span><br><span class="line">T java.lang.reflect.Proxy#newProxyInstance</span><br></pre></td></tr></table></figure>



<h2 id="SQL流图"><a href="#SQL流图" class="headerlink" title="SQL流图"></a>SQL流图</h2><h2 id="Select-流程"><a href="#Select-流程" class="headerlink" title="Select 流程"></a>Select 流程</h2><h3 id="建连"><a href="#建连" class="headerlink" title="建连"></a>建连</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:60)</span><br><span class="line">at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:337)</span><br><span class="line">at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)</span><br><span class="line">at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)</span><br><span class="line">at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325)</span><br><span class="line">at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)</span><br><span class="line">at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:103)</span><br><span class="line">at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89)</span><br><span class="line">at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151)</span><br><span class="line">at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145)</span><br><span class="line">at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)</span><br><span class="line">at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:76)</span><br><span class="line">at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:87)</span><br><span class="line">at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:145)</span><br><span class="line">at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86)</span><br><span class="line">at com.sun.proxy.$Proxy.select(Unknown Source:-1)</span><br></pre></td></tr></table></figure>

<h3 id="执行"><a href="#执行" class="headerlink" title="执行"></a>执行</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">org.apache.ibatis.executor.CachingExecutor#query(ms,parameterObject,rowBounds,resultHandler)</span><br><span class="line">org.apache.ibatis.executor.BaseExecutor#query(ms,parameter,rowBounds,resultHandler,key,boundSql)</span><br><span class="line">org.apache.ibatis.executor.BaseExecutor#queryFromDatabase</span><br><span class="line">org.apache.ibatis.executor.SimpleExecutor#doQuery</span><br><span class="line">org.apache.ibatis.executor.statement.RoutingStatementHandler#parameterize</span><br><span class="line">org.apache.ibatis.executor.statement.PreparedStatementHandler#parameterize</span><br><span class="line">org.apache.ibatis.scripting.defaults.DefaultParameterHandler#setParameters</span><br><span class="line">org.apache.ibatis.executor.statement.RoutingStatementHandler#query</span><br><span class="line">org.apache.ibatis.executor.resultset.DefaultResultSetHandler#handleResultSets</span><br></pre></td></tr></table></figure>

<p><font color="red">Executor &#x3D;&#x3D;&gt; Statement &#x3D;&#x3D;&gt; Parameter &#x3D;&#x3D;&gt; ResultSet</font></p>
<blockquote>
<p><em>绿色</em> 几个组件都是可以通过mybatis插件改写的，参考  <a target="_blank" rel="noopener" href="https://mybatis.org/mybatis-3/zh/configuration.html#plugins">mybatis plugin</a></p>
<ul>
<li><p>Executor (update, query, flushStatements, commit, rollback, getTransaction, close, isClosed)</p>
</li>
<li><p>StatementHandler (prepare, parameterize, batch, update, query)</p>
</li>
<li><p>ParameterHandler (getParameterObject, setParameters)</p>
</li>
<li><p>ResultSetHandler (handleResultSets, handleOutputParameters)</p>
</li>
</ul>
</blockquote>

      
    </div>
    <footer class="entry-meta entry-footer">
      
	<span class="ico-folder"></span>
    <a class="article-category-link" href="/categories/Mybatis/">Mybatis</a>

      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/MyBatis/" rel="tag">MyBatis</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-tcpdump-tshark"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2019/09/23/tcpdump-tshark/">tcpdump及tshark 使用</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2019/09/23/tcpdump-tshark/" class="article-date">
	  <time datetime="2019-09-23T11:19:37.000Z" itemprop="datePublished">九月 23, 2019</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="通用抓包工具"><a href="#通用抓包工具" class="headerlink" title="通用抓包工具"></a>通用抓包工具</h2><ol>
<li>tcpdump</li>
<li>tshark (wireshark 命令行版)</li>
</ol>
<h2 id="tshark-安装"><a href="#tshark-安装" class="headerlink" title="tshark 安装"></a>tshark 安装</h2><p><code>yum install -y wireshark</code></p>
<h2 id="http请求抓包"><a href="#http请求抓包" class="headerlink" title="http请求抓包"></a>http请求抓包</h2><ul>
<li>tcpdump方式：</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo tcpdump -A -s 0 &#x27;tcp port 8080 and (((ip[2:2] - ((ip[0]&amp;0xf)&lt;&lt;2)) - ((tcp[12]&amp;0xf0)&gt;&gt;2)) != 0)&#x27;</span><br></pre></td></tr></table></figure>

<ul>
<li>tshark方式：</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">加 -V 显示包体内容，否则仅url，response_code等</span></span><br><span class="line">sudo tshark -i eth0 -R &#x27;ip.addr ==100.100.17.97 and http&#x27;</span><br></pre></td></tr></table></figure>



<h2 id="mysql-抓包"><a href="#mysql-抓包" class="headerlink" title="mysql 抓包"></a>mysql 抓包</h2><ul>
<li>tcpdump方式</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">sudo tcpdump -i any -s 0 -l -w - dst port 3306 | strings | perl -e &#x27;</span><br><span class="line">while(&lt;&gt;) &#123; chomp; next if /^[^ ]+[ ]*$/;</span><br><span class="line">    if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL)/i)</span><br><span class="line">    &#123;</span><br><span class="line">        if (defined $q) &#123; print &quot;$q\n&quot;; &#125;</span><br><span class="line">        $q=$_;</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">        $_ =~ s/^[ \t]+//; $q.=&quot; $_&quot;;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;&#x27;</span><br></pre></td></tr></table></figure>

<ul>
<li>tshark方式</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">time_delta 本次回包耗时（RTT）</span></span><br><span class="line">sudo tshark -i eth0 -R &quot;ip.addr==ip&quot; -d tcp.port==3306,mysql -o tcp.calculate_timestamps:true -T fields -e frame.number -e frame.time_epoch -e frame.time_delta_displayed -e ip.src -e tcp.srcport -e ip.dst -e tcp.dstport -e tcp.time_delta -e tcp.stream -e tcp.len -e mysql.query</span><br></pre></td></tr></table></figure>




      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Linux/" rel="tag">Linux</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Net/" rel="tag">Net</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Tcpdump/" rel="tag">Tcpdump</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Tshark/" rel="tag">Tshark</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-tcpdump"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2019/09/23/tcpdump/">tcpdump及tshark 使用</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2019/09/23/tcpdump/" class="article-date">
	  <time datetime="2019-09-23T11:19:37.000Z" itemprop="datePublished">九月 23, 2019</time>
	</a>

       
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <p>译自 <a target="_blank" rel="noopener" href="https://danielmiessler.com/study/tcpdump/">A tcpdump Tutorial and Primer with Examples</a> 有所增删，可以通过 <code>man tcpdump</code> 获取更详细信息</p>
<p>只要和网络沾边，都可以使用tcpdump来排查问题。</p>
<h2 id="1-基础"><a href="#1-基础" class="headerlink" title="1  基础"></a>1  基础</h2><h3 id="1-1-常用选项"><a href="#1-1-常用选项" class="headerlink" title="1.1 常用选项"></a>1.1 常用选项</h3><ul>
<li><code>-i any</code> ：监听任意网络设备</li>
<li><code>-i eth0</code> ：监听eth0</li>
<li><code>-D</code> ：列出所有可监听设备</li>
<li><code>-n</code> ：不要把IP解析为主机名（显示IP）</li>
<li><code>-nn</code> ：不要把IP和PORT解析为主机名和服务（显示IP和端口）</li>
<li><code>-q</code> ：显示更少信息</li>
<li><code>-tttt</code> ：更具有可读性的时间格式</li>
<li><code>-X</code> ：以hex和ascii格式显示包内容</li>
<li><code>-XX</code> ：同 <code>-X</code> , 同时包含以太网协议头</li>
<li><code>-v, -vv, -vvv</code> ：显示更多信息</li>
<li><code>-c x</code> ：最多抓取x个包，然后退出</li>
<li><code>-A</code> ：以ASCII格式打印每个包（最小化link level的头）,适合抓web页面</li>
<li><code>-s</code> ：Define the snaplength (size) of the capture in bytes. 使用 <code>-s0</code> 获取全部</li>
<li><code>-w file</code> ：把结果输出到文件file</li>
<li><code>-S</code> ：Print absolute sequence numbers.</li>
</ul>
<h3 id="1-2-表达式"><a href="#1-2-表达式" class="headerlink" title="1.2 表达式"></a>1.2 表达式</h3><p>表达式用于过滤抓到的包，有三类表达式</p>
<ul>
<li>类型 <code>host</code> <code>net</code> <code>port</code></li>
<li>数据流向 <code>src</code> <code>dst</code></li>
<li>协议 <code>tcp</code> <code>udp</code> <code>icmp</code> 等</li>
</ul>
<h2 id="2-例子"><a href="#2-例子" class="headerlink" title="2 例子"></a>2 例子</h2><h3 id="2-1-获取所有流量"><a href="#2-1-获取所有流量" class="headerlink" title="2.1 获取所有流量"></a>2.1 获取所有流量</h3><p><code>tcpdump -i any</code> 当机器有多个网卡，不确定流量走哪个时，使用这个选项</p>
<h3 id="2-2-获取eth0上的流量"><a href="#2-2-获取eth0上的流量" class="headerlink" title="2.2 获取eth0上的流量"></a>2.2 获取eth0上的流量</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tcpdump -i eth0</span><br></pre></td></tr></table></figure>

<h3 id="2-3-查看原始流量"><a href="#2-3-查看原始流量" class="headerlink" title="2.3 查看原始流量"></a>2.3 查看原始流量</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tcpdump -nn -tttt -vv -S -c 10</span><br></pre></td></tr></table></figure>

<h3 id="2-4-查看指定host和port"><a href="#2-4-查看指定host和port" class="headerlink" title="2.4 查看指定host和port"></a>2.4 查看指定host和port</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tcpdump port 80 and host 10.129.204.105</span><br></pre></td></tr></table></figure>

<h3 id="2-5-以hex和ascii查看包内容"><a href="#2-5-以hex和ascii查看包内容" class="headerlink" title="2.5 以hex和ascii查看包内容"></a>2.5 以hex和ascii查看包内容</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tcpdump -nn -v -X -s0 -c 1 tcp</span><br></pre></td></tr></table></figure>

<h3 id="2-6-指定数据的方向"><a href="#2-6-指定数据的方向" class="headerlink" title="2.6 指定数据的方向"></a>2.6 指定数据的方向</h3><p>获取所有目标端口是80的流量 <code>tcpdump -i any -nn -s0 -c 10 -A tcp and dst port 80</code></p>
<p>获取所有80端口的流量 <code>tcpdump -i any -nn -s0 -c 10 -A tcp and port 80</code></p>
<h3 id="2-7-获取指定协议的流量"><a href="#2-7-获取指定协议的流量" class="headerlink" title="2.7 获取指定协议的流量"></a>2.7 获取指定协议的流量</h3><p>获取vrrp协议的流量，用于调试keepalive <code>tcpdump vrrp</code></p>
<h3 id="2-8-获取ipv6的流量"><a href="#2-8-获取ipv6的流量" class="headerlink" title="2.8 获取ipv6的流量"></a>2.8 获取ipv6的流量</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tcpdump ip6</span><br></pre></td></tr></table></figure>

<h3 id="2-9-获取某个端口范围的流量"><a href="#2-9-获取某个端口范围的流量" class="headerlink" title="2.9 获取某个端口范围的流量"></a>2.9 获取某个端口范围的流量</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tcpdump -nn portrange 21-23 and src host 10.136.110.179</span><br></pre></td></tr></table></figure>

<h3 id="2-10-基于包大小过滤"><a href="#2-10-基于包大小过滤" class="headerlink" title="2.10 基于包大小过滤"></a>2.10 基于包大小过滤</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">tcpdump -i any -nn port 80 and less 80</span><br><span class="line">tcpdump -i any -nn port 80 and greater 80</span><br></pre></td></tr></table></figure>

<h2 id="3-进阶"><a href="#3-进阶" class="headerlink" title="3 进阶"></a>3 进阶</h2><h3 id="3-1-表达式组合"><a href="#3-1-表达式组合" class="headerlink" title="3.1 表达式组合"></a>3.1 表达式组合</h3><p>通过 <code>and 或 &amp;&amp;</code> <code>or 或 ||</code> <code>not 或 ！</code> 可以组合表达式</p>
<p>表达式的结合律有点奇怪，需要自己体会，例如： 监听80或8080并且来自10.129.204.105的请求 <code>tcpdump -i any -nn -vv port 80 or 8080 and src host 10.129.204.105</code> <code>tcpdump -i any -nn -vv port 80 or port 8080 and src host 10.129.204.105</code></p>
<p>监听80并且来自10.129.204.105的请求或监听8080的请求（没有来源IP限制） <code>tcpdump -i any -nn -vv port 80 and src host 10.129.204.105 or port 8080</code></p>
<p>为了避免这些微妙的差别，可以使用 <code>()</code> ，注意这里的单引号 <code>tcpdump -i any -nn -vv &#39;(port 80 or port 8080)&#39; and src host 10.129.204.105</code></p>
<h3 id="3-2-指定源host和目标端口"><a href="#3-2-指定源host和目标端口" class="headerlink" title="3.2 指定源host和目标端口"></a>3.2 指定源host和目标端口</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tcpdump -i any -nn -vv port 80 and src host 10.129.204.105</span><br></pre></td></tr></table></figure>

<h3 id="3-3-目标是某台机器的所有非tcp请求"><a href="#3-3-目标是某台机器的所有非tcp请求" class="headerlink" title="3.3 目标是某台机器的所有非tcp请求"></a>3.3 目标是某台机器的所有非tcp请求</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tcpdump -i any -nn dst host 10.136.110.179 and not tcp</span><br></pre></td></tr></table></figure>

<h3 id="3-4-来自某台机器的所有非22请求"><a href="#3-4-来自某台机器的所有非22请求" class="headerlink" title="3.4 来自某台机器的所有非22请求"></a>3.4 来自某台机器的所有非22请求</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tcpdump -i any -nn src host 10.129.204.105 and not dst port 22</span><br></pre></td></tr></table></figure>

<h3 id="3-5-获取tcp-flag"><a href="#3-5-获取tcp-flag" class="headerlink" title="3.5 获取tcp flag"></a>3.5 获取tcp flag</h3><p>先了解下TCP和IP协议头，虽然最后有0~40个可选bytes，这里没用到，可以先忽略它们。TCP头20bytes，其中tcp flags在第13个byte（下标为0） <code>|C|E|U|A|P|R|S|F|</code> 。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">TCP</span><br><span class="line"> 0                            15                              31</span><br><span class="line">-----------------------------------------------------------------</span><br><span class="line">|          source port          |       destination port        |</span><br><span class="line">-----------------------------------------------------------------</span><br><span class="line">|                        sequence number                        |</span><br><span class="line">-----------------------------------------------------------------</span><br><span class="line">|                     acknowledgment number                     |</span><br><span class="line">-----------------------------------------------------------------</span><br><span class="line">|  HL   | rsvd  |C|E|U|A|P|R|S|F|        window size            |</span><br><span class="line">-----------------------------------------------------------------</span><br><span class="line">|         TCP checksum          |       urgent pointer          |</span><br><span class="line">-----------------------------------------------------------------</span><br><span class="line">|                 optional data 0~40 bytes                      |</span><br><span class="line">-----------------------------------------------------------------</span><br><span class="line"></span><br><span class="line"> |---------------|</span><br><span class="line"> |C|E|U|A|P|R|S|F|</span><br><span class="line"> |---------------|</span><br><span class="line"> |7   5   3     0|</span><br><span class="line"></span><br><span class="line">IP</span><br><span class="line">  0| 1| 2| 3| 4| 5| 6| 7| 8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31</span><br><span class="line">-----------------------------------------------------------------------------------------------</span><br><span class="line">| version   |    IHL    |      DSCP       | ECN |             total length                     </span><br><span class="line">-----------------------------------------------------------------------------------------------</span><br><span class="line">|             Identification                    | Flags  |       Fragment Offset               </span><br><span class="line">-----------------------------------------------------------------------------------------------</span><br><span class="line">|          TTL          |      Protocol         |               Header Checksum                </span><br><span class="line">-----------------------------------------------------------------------------------------------</span><br><span class="line">|                                         Source IP                                            </span><br><span class="line">-----------------------------------------------------------------------------------------------</span><br><span class="line">|                                        Destination IP                                        </span><br><span class="line">-----------------------------------------------------------------------------------------------</span><br></pre></td></tr></table></figure>

<h4 id="3-5-1-flag列表"><a href="#3-5-1-flag列表" class="headerlink" title="3.5.1 flag列表"></a>3.5.1 flag列表</h4><ul>
<li>URGENT (URG) <code>tcp[13] &amp; 32 != 0</code> 或 <code>tcp[tcpflags] == tcp-urg</code></li>
<li>ACKNOWLEDGE (ACK) <code>tcp[13] &amp; 16 != 0</code> 或 <code>tcp[tcpflags] == tcp-ack</code></li>
<li>PUSH (PSH) <code>tcp[13] &amp; 8 != 0</code> 或 <code>tcp[tcpflags] == tcp-psh</code></li>
<li>RESET (RST) <code>tcp[13] &amp; 4 != 0</code> 或 <code>tcp[tcpflags] == tcp-rst</code></li>
<li>SYNCHRONIZE (SYN) <code>tcp[13] &amp; 2 != 0</code> 或 <code>tcp[tcpflags] == tcp-syn</code></li>
<li>FINISH (FIN) <code>tcp[13] &amp; 1 != 0</code> 或 <code>tcp[tcpflags] == tcp-fin</code></li>
</ul>
<p>例如：获取所有SYN请求 <code>tcpdump -i any -nn -A -s0 &#39;tcp[13] &amp; 2 != 0&#39;</code></p>
<h4 id="3-5-2-获取tcp连接的开始和结束"><a href="#3-5-2-获取tcp连接的开始和结束" class="headerlink" title="3.5.2 获取tcp连接的开始和结束"></a>3.5.2 获取tcp连接的开始和结束</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tcpdump -i any -nn -s0 -X &#x27;tcp[tcpflags] &amp; (tcp-syn|tcp-fin) != 0&#x27;</span><br></pre></td></tr></table></figure>

<h4 id="3-5-3-获取所有HTTP-GET请求"><a href="#3-5-3-获取所有HTTP-GET请求" class="headerlink" title="3.5.3 获取所有HTTP GET请求"></a>3.5.3 获取所有HTTP GET请求</h4><p><code>tcp[12]</code> 的高4位是TCP HEADER的长度（通常是20 bytes）,TCP之后是应用协议 <code>0x47455420</code> 是 GET 外加一个空格 <code>tcpdump -i any -nn -s0 -X &#39;tcp[((tcp[12] &amp; 0xf0) &gt;&gt; 2):4] = 0x47455420&#39;</code> 通常 <code>tcpdump -i any -nn -s0 -X &#39;tcp[20:4] = 0x47455420&#39;</code> 也是可以的</p>
<h4 id="3-5-4-获取所有SSH连接"><a href="#3-5-4-获取所有SSH连接" class="headerlink" title="3.5.4 获取所有SSH连接"></a>3.5.4 获取所有SSH连接</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">0x5353482D` 是 `SSH-` `tcpdump -i any -nn -s0 -X &#x27;tcp[20:4] = 0x5353482D&#x27;</span><br></pre></td></tr></table></figure>

<h4 id="3-5-5-获取所有带数据的包"><a href="#3-5-5-获取所有带数据的包" class="headerlink" title="3.5.5 获取所有带数据的包"></a>3.5.5 获取所有带数据的包</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ip[2:2]` 整个IP包的长度 `(ip[0] &amp; 0xf) &lt;&lt;2` 是IP头的长度 `tcpdump -i any -nn -s0 -X port 80 and &#x27;(((ip[2:2] - ((ip[0]&amp;0xf)&lt;&lt;2)) - ((tcp[12]&amp;0xf0)&gt;&gt;2)) != 0)&#x27;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="entry-meta entry-footer">
      
      
  <span class="ico-tags"></span>
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Linux/" rel="tag">Linux</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Net/" rel="tag">Net</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Tcpdump/" rel="tag">Tcpdump</a></li></ul>

      
    </footer>
    <hr class="entry-footer-hr">
  </div>
  
</article>

<!-- Table of Contents -->

  


  <nav id="page-nav">
    
    <a class="extend prev" rel="prev" href="/">上一页</a><a class="page-number" href="/">1</a><span class="page-number current">2</span><a class="page-number" href="/page/3/">3</a><a class="extend next" rel="next" href="/page/3/">下一页</a>
  </nav>

</section>
          <aside id="sidebar">
  
    <div style="margin: 20px 0;">
	<div id="search-form-wrap">

    <form class="search-form">
        <label style="width: 72%;">
            <span class="screen-reader-text">Search for:</span>
            <input type="search" class="search-field" style="height: 36px; width: 100%;" placeholder=" 搜索…" value="" name="s" title="Search for:">
        </label>
        <input type="submit" class="search-form-submit" value="搜索">
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="请输入关键词..."/>
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(无标题)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/js/insight.js"></script>


</div>
</div>
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">联系我们</h3>
    <div class="widget widget_athemes_social_icons">

    	<ul class="clearfix widget-social-icons">   
    	
   			<li><a target="_blank" rel="noopener" href="https://github.com/iTimeTraveler" title="Github"><i class="fa fa-github" aria-hidden="true"></i></a></li> 

   		
   			<li><a href="" title="Weibo"><i class="fa fa-weibo" aria-hidden="true"></i></a></li> 

   		
   			<li><a href="" title="Twitter"><i class="fa fa-twitter" aria-hidden="true"></i></a></li> 

   		
   			<li><a href="" title="Facebook"><i class="fa fa-facebook" aria-hidden="true"></i></a></li> 

   		
   			<li><a href="" title="Google-plus"><i class="fa fa-google-plus" aria-hidden="true"></i></a></li> 

   		
   			<li><a href="" title="Instagram"><i class="fa fa-instagram" aria-hidden="true"></i></a></li> 

   		
   		</ul>


   		<!--
   		<ul class="clearfix widget-social-icons">   		
   		<li class="widget-si-twitter"><a target="_blank" rel="noopener" href="http://twitter.com" title="Twitter"><i class="ico-twitter"></i></a></li> 
		<li class="widget-si-facebook"><a target="_blank" rel="noopener" href="http://facebook.com" title="Facebook"><i class="ico-facebook"></i></a></li>
			<li class="widget-si-gplus"><a target="_blank" rel="noopener" href="http://plus.google.com" title="Google+"><i class="ico-gplus"></i></a></li>
			<li class="widget-si-pinterest"><a target="_blank" rel="noopener" href="http://pinterest.com" title="Pinterest"><i class="ico-pinterest"></i></a></li>
			<li class="widget-si-flickr"><a target="_blank" rel="noopener" href="http://flickr.com" title="Flickr"><i class="ico-flickr"></i></a></li>
			<li class="widget-si-instagram"><a target="_blank" rel="noopener" href="http://instagram.com" title="Instagram"><i class="ico-instagram"></i></a></li>
		</ul> -->

    </div>
  </div>


  
    
  <div class="widget_athemes_tabs">
    <ul id="widget-tab" class="clearfix widget-tab-nav">
      <li class="active"><a>最新文章</a></li>
    </ul>
    <div class="widget">
      <ul>
        
          <li class="clearfix">

            
              <div class="widget-entry-summary" style="margin: 0;">
            

              <h6 style="margin: 0;"><a href="/2022/04/22/debug-mysql-with-clion/">使用Clion调试MySQL Server源码</a></h6>
              <span>四月 22, 2022</span>
            </div>

          </li>
        
          <li class="clearfix">

            
              <div class="widget-entry-summary" style="margin: 0;">
            

              <h6 style="margin: 0;"><a href="/2021/08/12/dev-prepare/">通用开发环境搭建</a></h6>
              <span>八月 12, 2021</span>
            </div>

          </li>
        
          <li class="clearfix">

            
              <div class="widget-entry-summary" style="margin: 0;">
            

              <h6 style="margin: 0;"><a href="/2021/08/11/zsh/">安装zsh及主题(Mac)</a></h6>
              <span>八月 11, 2021</span>
            </div>

          </li>
        
          <li class="clearfix">

            
              <div class="widget-entry-summary" style="margin: 0;">
            

              <h6 style="margin: 0;"><a href="/2021/06/30/mysql-architecture/">MySQL-architecture</a></h6>
              <span>六月 30, 2021</span>
            </div>

          </li>
        
          <li class="clearfix">

            
              <div class="widget-entry-summary" style="margin: 0;">
            

              <h6 style="margin: 0;"><a href="/2021/01/12/docker-net/">docker_net</a></h6>
              <span>一月 12, 2021</span>
            </div>

          </li>
        
          <li class="clearfix">

            
              <div class="widget-entry-summary" style="margin: 0;">
            

              <h6 style="margin: 0;"><a href="/2020/08/26/jdb/">jdb</a></h6>
              <span>八月 26, 2020</span>
            </div>

          </li>
        
      </ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">分类</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Git/">Git</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Mybatis/">Mybatis</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%BB%BA%E7%AB%99/">建站</a><span class="category-list-count">2</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Endian-%E5%AD%97%E8%8A%82%E5%BA%8F-%E7%BD%91%E7%BB%9C%E9%80%9A%E4%BF%A1/" rel="tag">Endian 字节序 网络通信</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Git/" rel="tag">Git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/GitHub-PR/" rel="tag">GitHub PR</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Linux/" rel="tag">Linux</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Linux-Iptables-Netstat-%E7%AB%AF%E5%8F%A3/" rel="tag">Linux Iptables Netstat 端口</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Linux-diff-comm-grep/" rel="tag">Linux diff comm grep</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MyBatis/" rel="tag">MyBatis</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MySQL-architecture/" rel="tag">MySQL architecture</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Mybatis-MySQL/" rel="tag">Mybatis MySQL</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Mybatis-Proxy/" rel="tag">Mybatis Proxy</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Net/" rel="tag">Net</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Tcpdump/" rel="tag">Tcpdump</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Tshark/" rel="tag">Tshark</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/binlog-protocol/" rel="tag">binlog protocol</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/debug-jdb/" rel="tag">debug jdb</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker-mysql/" rel="tag">docker mysql</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker-net/" rel="tag">docker net</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java-maven-docker-mysql-gitlab-github/" rel="tag">java maven docker mysql gitlab github</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/jvm-classloader/" rel="tag">jvm classloader</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql-binlog-xa/" rel="tag">mysql binlog xa</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql-server/" rel="tag">mysql server</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql-server-debug-clion/" rel="tag">mysql-server debug clion</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx/" rel="tag">nginx</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx-%E7%81%B0%E5%BA%A6/" rel="tag">nginx 灰度</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zsh-oh-my-zsh/" rel="tag">zsh oh-my-zsh</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%BB%BA%E7%AB%99/" rel="tag">建站</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签云</h3>
    <div class="widget tagcloud">
      <a href="/tags/Endian-%E5%AD%97%E8%8A%82%E5%BA%8F-%E7%BD%91%E7%BB%9C%E9%80%9A%E4%BF%A1/" style="font-size: 10px;">Endian 字节序 网络通信</a> <a href="/tags/Git/" style="font-size: 20px;">Git</a> <a href="/tags/GitHub-PR/" style="font-size: 10px;">GitHub PR</a> <a href="/tags/Linux/" style="font-size: 20px;">Linux</a> <a href="/tags/Linux-Iptables-Netstat-%E7%AB%AF%E5%8F%A3/" style="font-size: 10px;">Linux Iptables Netstat 端口</a> <a href="/tags/Linux-diff-comm-grep/" style="font-size: 10px;">Linux diff comm grep</a> <a href="/tags/MyBatis/" style="font-size: 10px;">MyBatis</a> <a href="/tags/MySQL-architecture/" style="font-size: 10px;">MySQL architecture</a> <a href="/tags/Mybatis-MySQL/" style="font-size: 10px;">Mybatis MySQL</a> <a href="/tags/Mybatis-Proxy/" style="font-size: 10px;">Mybatis Proxy</a> <a href="/tags/Net/" style="font-size: 20px;">Net</a> <a href="/tags/Tcpdump/" style="font-size: 20px;">Tcpdump</a> <a href="/tags/Tshark/" style="font-size: 10px;">Tshark</a> <a href="/tags/binlog-protocol/" style="font-size: 10px;">binlog protocol</a> <a href="/tags/debug-jdb/" style="font-size: 10px;">debug jdb</a> <a href="/tags/docker-mysql/" style="font-size: 10px;">docker mysql</a> <a href="/tags/docker-net/" style="font-size: 10px;">docker net</a> <a href="/tags/java-maven-docker-mysql-gitlab-github/" style="font-size: 10px;">java maven docker mysql gitlab github</a> <a href="/tags/jvm-classloader/" style="font-size: 10px;">jvm classloader</a> <a href="/tags/mysql-binlog-xa/" style="font-size: 10px;">mysql binlog xa</a> <a href="/tags/mysql-server/" style="font-size: 10px;">mysql server</a> <a href="/tags/mysql-server-debug-clion/" style="font-size: 10px;">mysql-server debug clion</a> <a href="/tags/nginx/" style="font-size: 10px;">nginx</a> <a href="/tags/nginx-%E7%81%B0%E5%BA%A6/" style="font-size: 10px;">nginx 灰度</a> <a href="/tags/zsh-oh-my-zsh/" style="font-size: 10px;">zsh oh-my-zsh</a> <a href="/tags/%E5%BB%BA%E7%AB%99/" style="font-size: 10px;">建站</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>

    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2022/04/">四月 2022</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/08/">八月 2021</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/06/">六月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/01/">一月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/08/">八月 2020</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/07/">七月 2020</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/06/">六月 2020</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/04/">四月 2020</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/11/">十一月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">十月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/09/">九月 2019</a><span class="archive-list-count">9</span></li></ul>
    </div>
  </div>


  
</aside>
        
      </div>

    </div>
    <!-- <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/categories" class="mobile-nav-link">Categories</a>
  
    <a href="/tags" class="mobile-nav-link">Tags</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav> -->
    <footer id="footer" class="site-footer">
  

  <div class="clearfix container">
      <div class="site-info">
		<a href="https://beian.miit.gov.cn/" target="_blank">鄂ICP备2023005434号-1</a>  	
	        Copyright &copy; 2023 YouN 科技温度 All Rights Reserved.
        
            <span id="busuanzi_container_site_uv">
              本站访客数<span id="busuanzi_value_site_uv"></span>人次  
              本站总访问量<span id="busuanzi_value_site_pv"></span>次
            </span>
          
      </div>
      <div class="site-credit">
        Theme by <a href="https://github.com/iTimeTraveler/hexo-theme-hipaper" target="_blank">hipaper</a>
      </div>
  </div>
</footer>


<!-- min height -->

<script>
    var wrapdiv = document.getElementById("wrap");
    var contentdiv = document.getElementById("content");

    wrapdiv.style.minHeight = document.body.offsetHeight - document.getElementById("allheader").offsetHeight - document.getElementById("footer").offsetHeight + "px";
    contentdiv.style.minHeight = document.body.offsetHeight - document.getElementById("allheader").offsetHeight - document.getElementById("footer").offsetHeight + "px";


    <!-- headerblur min height -->
    
    
</script>

    
<div style="display: none;">
  <script src="https://s11.cnzz.com/z_stat.php?id=1260716016&web_id=1260716016" language="JavaScript"></script>
</div>

<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">

  
<script src="/fancybox/jquery.fancybox.pack.js"></script>




<script src="/js/script.js"></script>


<script src="/js/bootstrap.js"></script>


<script src="/js/main.js"></script>








  <div style="display: none;">
    <script src="https://s95.cnzz.com/z_stat.php?id=1260716016&web_id=1260716016" language="JavaScript"></script>
  </div>



	<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
	</script>






  </div>

  <a id="rocket" href="#top" class=""></a>
  <script type="text/javascript" src="/js/totop.js" async=""></script>
</body>
</html>
